package com.augurit.smartform.converter;

import java.util.ArrayList;
import java.util.List;

import com.augurit.common.base.extmodel.inner.AppTreeNode;
import com.augurit.common.entity.AcModule;
import com.augurit.common.system.convert.AcModuleConverter;
import com.augurit.common.system.util.OrgUtils;
import com.augurit.common.system.web.org.form.AcModuleForm;
import com.augurit.smartform.entity.SmPageDir;
import com.augurit.smartform.mgmt.SmartPageTreeNode;
import com.augurit.smartform.web.parser.form.SmPageDirForm;

public class PageDirConverter {
	/**
	 * 将form对象的值加入到实体对象中
	 * @param form
	 * @param entity
	 */
	public static void convertToEntity(SmPageDirForm form,SmPageDir entity){
		if(form!=null&&entity!=null){
			entity.setName(form.getName());
			entity.setParentId(form.getParentId());
		}
	}
	
	/**
	 * 将实体转换为form对象
	 * @param entity
	 * @return
	 */
	public static SmPageDirForm convertToForm(SmPageDir entity){
		if(entity!=null){
			SmPageDirForm form=new SmPageDirForm();
			form.setId(entity.getId());
			form.setName(entity.getName());
			form.setParentId(entity.getParentId());
			return form;
		}else{
			return null;
		}
	}
	
	/**
	 * 将实体对象列表转换为form对象列表
	 * @param list
	 * @return
	 */
	public static List<SmPageDirForm> convertToFormList(List<SmPageDir> list){
		if(list != null && list.size() > 0){
			List<SmPageDirForm> result = new ArrayList<SmPageDirForm>();
			
			for(SmPageDir entity : list){
				SmPageDirForm form = convertToForm(entity);
				
				result.add(form);
			}
			
			return result;
		}else{
			return null;
		}	
	}
	
	/**
	 * 将Form对象列表转换为ExtTreeNode对象列表
	 * @param form
	 * @return
	 */
	public static SmartPageTreeNode convertPageDirToTreeNode(SmPageDirForm form){
		if(form != null){
			SmartPageTreeNode node = new SmartPageTreeNode();
			node.setId(SmartPageTreeNode.getKey(SmPageDir.class.getSimpleName(), form.getId()));
			node.setText(form.getName());
			node.setQtip(form.getName());
			node.setIconCls(SmartPageTreeNode.CLS_MODULE);
			node.setLeaf(false);
			return node;
		}else{
			return null;
		}	
	}
	
	/**
	 * 将Form对象列表转换为ExtTreeNode对象列表
	 * @param list
	 * @return
	 */
	public static List<SmartPageTreeNode> convertPageDirToTreeNode(List<SmPageDirForm> list){
		List<SmartPageTreeNode> result = new ArrayList<SmartPageTreeNode>();
		if(list != null && list.size() > 0){
			for(SmPageDirForm pageDir : list)
				result.add(PageDirConverter.convertPageDirToTreeNode(pageDir));
		}
		return result;
	}
}
